/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package package4;

import java.io.*;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Scanner;

/**
 *
 * @author BEAST
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        LinkedList<MyVector> testCase = new LinkedList<MyVector>();
        
        final String INPUT_PROMPT =
            "Please enter the path of the file to read in the MyVector objects: ";
               
        Scanner keyboardScanner = new Scanner (System.in), //Read in the filename
                fileScanner = null; //Read in the filename
        
        String fileName = null; //Filename that contains MyVector objects
        
        try //Grab user input from System.in to open file
            {
                System.out.print (INPUT_PROMPT);  
                fileName = keyboardScanner.next(); //Wait for input of filename by user
                fileScanner = new Scanner (new File (fileName)); //Create scanner object with filename
            } // try
        catch (IOException e)
            {
                System.out.println ("\n" + e);
            } // catch IOException
        
        int vectorQty = 0;
        int vectorDepth = 0;
        
        try //Begin populating the testCase LinkedList double by double
            {
                vectorQty = fileScanner.nextInt(); //Line 1 of txt file. Quantity of vectors in the file
                vectorDepth = fileScanner.nextInt(); //Line 2 of txt file. Quantity of elements of the vectors
                
                for (int i = 0; i < vectorQty; i++)  //Loop through each MyVector
                {
                    double[] tempArray = new double[vectorDepth];
                    for (int n = 0; n < vectorDepth; n++) //Loop through each element of MyVector
                        {
                            tempArray[n] = fileScanner.nextDouble(); //Add each double to an array
                        }
                    testCase.addLast(new MyVector(tempArray)); //Add newly instantiated MyVector to the LinkedList
                }
            }
        catch (InputMismatchException e) //TODO :: If something is caught undo that vector and continue on (need to review chapter)
            {
                System.out.println(e);
            }
        
        
        ListIterator itrFront = testCase.listIterator(); //Iterator starting at the beginning of the LinkedList
        ListIterator itrBack  = testCase.listIterator(vectorQty); //Iterator started at the end of the LinkedList
        
        while(itrFront.hasNext()) //Loop through as long as itrFront hasNext() or until it breaks
        {
            if(!itrFront.next().toString().equals(itrBack.previous().toString()))
            {
                System.out.println("Not palindrome");
                break; //Break the while loop if the if statement is correct (if the two are not equal)
            }
        }
        
        if(!itrFront.hasNext()) //If the iterator still has a next element the previous while loop never completely finished
        {
            System.out.println("Palindrome");
        }
        
        
    }
    
    
}
